import { RoleService } from './role.service'
import { Body, Controller, Delete, Get, ParseArrayPipe, Post, Put, Query } from '@nestjs/common'
import { AuthRolePermissionDTO, CreateRoleDTO, RequirePermission, RoleEntity, TableQuery, UpdateRoleDTO } from '@/common'

@Controller('system/role')
export class RoleController {
  constructor(private readonly roleService: RoleService) {}

  /** 新增角色 */
  @RequirePermission(['system:role:create'])
  @Post('create')
  public create(@Body() createDto: CreateRoleDTO) {
    return this.roleService.create(createDto)
  }

  /** 根据传入 id 组删除单个或者多个数据 */
  @RequirePermission(['system:role:delete'])
  @Delete('delete')
  public delete(@Query('roleIds', new ParseArrayPipe()) roleIds: string[]) {
    return this.roleService.delete(roleIds)
  }

  /** 更新角色信息 */
  @RequirePermission(['system:role:update'])
  @Put('update')
  public update(@Body() updateDto: UpdateRoleDTO) {
    return this.roleService.update(updateDto)
  }

  /** 授权角色菜单权限 */
  @RequirePermission(['system:role:update'])
  @Post('authPermission')
  public authPermission(@Body() authDto: AuthRolePermissionDTO) {
    return this.roleService.authPermission(authDto)
  }

  /** 查询角色分页列表 */
  @RequirePermission(['system:role:query'])
  @Get('list')
  public findList(@TableQuery() queryParams: TableQueryParams<RoleEntity>) {
    return this.roleService.findList(queryParams)
  }

  /** 查询角色不分页列表 */
  @RequirePermission(['system:role:query'])
  @Get('all')
  public findAll() {
    return this.roleService.findAll()
  }

  /** 根据角色 ID 查找其详情 */
  @RequirePermission(['system:role:query'])
  @Get('detail')
  public findOneById(@Query('roleId') roleId: string) {
    return this.roleService.findOneById(roleId)
  }
}
